package day_2022_4_to_7.day48;

import java.util.Scanner;

/**
 * 扑克牌大小
 * @author haomin
 * @date 2022/05/12 20:57
 **/
public class Day16_2_ComparePokerSize {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String[] twoStr = str.split("-");
        int[] strLeft = changeToNum(twoStr[0]);
        int[] strRight = changeToNum(twoStr[1]);
        // 判断大小 默认 left 大则为1，right 大则为2，不存在关系 0
        if(CompareTow(strLeft,strRight) == 1){
            System.out.println(twoStr[0]);
        }else if(CompareTow(strLeft,strRight) == 2){
            System.out.println(twoStr[1]);
        }else {
            System.out.println("ERROR");
        }
    }

    private static int CompareTow(int[] strLeft, int[] strRight) {
        int len1 = strLeft.length;
        int len2 = strRight.length;

        // 排除大小王
        if(len1 == 2 && strLeft[0] + strLeft[1] == 29){
            return 1;
        }
        if(len2 == 2 && strRight[0] + strRight[1] == 29){
            return 2;
        }

        // 排除炸弹和非炸弹
        if(len1 == 4 && len2 != 4){
            return 1;
        }
        if(len1 != 4 && len2 == 4){
            return 2;
        }

        if(len1 == len2){
            return strLeft[0] > strRight[0] ? 1 : 2;
        }
        return 0;
    }


    private static int[] changeToNum(String s) {
        String[] data = s.split(" ");
        for (int i = 0; i < data.length; i++) {
            change(data,i);
        }
        int[] cur = new int[data.length];
        for (int i = 0; i < data.length; i++) {
            //System.out.println(Integer.valueOf(data[i]));
            cur[i] = Integer.valueOf(data[i]);
        }
        return cur;
    }

    private static void change(String[] data, int i) {
        if(data[i].equals("3")) data[i] = "0";
        if(data[i].equals("4")) data[i] = "1";
        if(data[i].equals("5")) data[i] = "3";
        if(data[i].equals("6")) data[i] = "4";
        if(data[i].equals("7")) data[i] = "5";
        if(data[i].equals("8")) data[i] = "6";
        if(data[i].equals("9"))data[i] = "7";
        if(data[i].equals("10")) data[i] = "8";
        if(data[i].equals("J")) data[i] = "9";
        if(data[i].equals("Q"))data[i] = "10";
        if(data[i].equals("K"))data[i] = "11";
        if(data[i].equals("A"))data[i] = "12";
        if(data[i].equals("2")) data[i] = "13";
        if(data[i].equals("joker")) data[i] = "14";
        if(data[i].equals("JOKER")) data[i] = "15";
    }
}